package middle;

public class Solution_673 {

    public int findNumberOfLIS(int[] nums) {
        int maxLength = 1, maxLengthNum = 0;
        int[][] counts = new int[nums.length][2];
        for (int i = 0; i < nums.length; i++) {
            // ints[0] 包含当前位置的最长严格递增子序列的长度；ints[1] 包含当前位置的最长严格递增子序列的长度的子序列数
            int[] ints = new int[]{1, 1};
            for (int j = i - 1; j >= 0; j--) {
                if (nums[j] < nums[i]) {
                    if (counts[j][0] + 1 > ints[0]) {
                        ints[0] = counts[j][0] + 1;
                        ints[1] = counts[j][1];
                    } else if (counts[j][0] + 1 == ints[0]) {
                        ints[1] += counts[j][1];
                    }
                }
            }
            maxLength = Math.max(ints[0], maxLength);
            counts[i] = ints;
        }
        for (int[] count : counts) {
            if (count[0] == maxLength) {
                maxLengthNum += count[1];
            }
        }
        for (int i = 0; i < counts.length; i++) {
            System.out.println("i = " + i + ";  num = " + nums[i] + ";  count[0] = " + counts[i][0] + ";  count[1] = " + counts[i][1]);
        }
        return maxLengthNum;
    }

    public static void main(String[] args) {
        Solution_673 model = new Solution_673();
        System.out.println(model.findNumberOfLIS(new int[]{1, 3, 5, 4, 7}));
        System.out.println(model.findNumberOfLIS(new int[]{2, 2, 2, 2, 2}));
    }
}
